package org.hdl.anima.proxy;

import java.io.IOException;

import org.hdl.anima.common.io.InputArchive;
import org.hdl.anima.common.io.OutputArchive;
import org.hdl.anima.common.io.Record;

/**
 * 
 * @author qiuhd
 * @since  2014年8月13日
 */
public class PackageHeader implements Record{
	
	public static final int LENGTH = (Byte.SIZE / 8) * 2  + (Integer.SIZE / 8) * 2 ;
	
	private int length;				//包长度
	private byte encrypted;			//压缩:0.没有压缩 1.压缩
	private byte type;				//包类型
	private int receiver;			//包接送者
	
	@Override
	public void serialize(OutputArchive archive) throws IOException {
		archive.writeInt(length);
		archive.writeByte(encrypted);
		archive.writeByte(type);
		archive.writeInt(receiver);

	}

	@Override
	public void deserialize(InputArchive archive) throws IOException {
		length = archive.readInt();
		encrypted = archive.readByte();
		type = archive.readByte();
		receiver = archive.readInt();
	}

	public boolean isEncrypted() {
		return encrypted == 1 ? true : false;
	}

	public void setEncrypted(boolean encrypted) {
		if(encrypted) {
			this.encrypted = 1;
		}else {
			this.encrypted = 0;
		}
	}

	public byte getType() {
		return type;
	}

	public void setType(byte type) {
		this.type = type;
	}

	public int getReceiver() {
		return receiver;
	}

	public void setReceiver(int receiver) {
		this.receiver = receiver;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}
}

